package com.wokeMy.view.adpter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zhongcai.online.R;

import java.util.ArrayList;

/**
 * Created by Administrator on 2018/2/6 0006.
 */

public class OpenHorLvAdapter extends BaseAdapter {
    private LayoutInflater inflater;
    ArrayList<String> data;
    private String qsize; //前区的个数
    private String lotteryId,type;
    private Context context;
     public OpenHorLvAdapter(Context context, ArrayList<String> data, String qsize,String lotteryId,String type) {
        this.inflater = LayoutInflater.from(context);
        this.context=context;
        this.data=data;
        this.qsize =qsize;
        this.lotteryId =lotteryId;
         this.type =type;
    }




    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHold viewHold;
        if (convertView==null){
            viewHold=new ViewHold();
            convertView=inflater.inflate(R.layout.item_item_ball_hrlv,null);
            viewHold.tvBall=(TextView)convertView.findViewById(R.id.ball_item_item_tv_hlv);
            viewHold.tvSum=(TextView)convertView.findViewById(R.id.sum_item_item_tv_hlv);
            convertView.setTag(viewHold);
        }else {
            viewHold=(ViewHold)convertView.getTag();
        }
        if (qsize.equals(data.size()+"")){
            //赢快3
            if (position==(data.size()-1)){
                if (type.equals("1")){
                    viewHold.tvSum.setVisibility(View.VISIBLE);
                    viewHold.tvSum.setText(lotteryId); //这里是和值
                }else {
                    viewHold.tvSum.setVisibility(View.GONE);
                }
            }
            switch (data.get(position)) {
                case "1":
                    viewHold.tvBall.setBackgroundResource(R.mipmap.one_dice);
                    break;
                case "2":
                    viewHold.tvBall.setBackgroundResource(R.mipmap.two_dice);
                    break;
                case "3":
                    viewHold.tvBall.setBackgroundResource(R.mipmap.three_dice);
                    break;
                case "4":
                    viewHold.tvBall.setBackgroundResource(R.mipmap.four_dice);
                    break;
                case "5":
                    viewHold.tvBall.setBackgroundResource(R.mipmap.five_dice);
                    break;
                case "6":
                    viewHold.tvBall.setBackgroundResource(R.mipmap.six_dice);
                    break;
                default:
                    viewHold.tvBall.setBackgroundResource(R.mipmap.one_dice);
                    break;
            }
            
        }else{
            if (position>(Integer.valueOf(qsize)-1)){
                viewHold.tvBall.setBackgroundResource(R.mipmap.blue_ball_bg);
            }else {
                viewHold.tvBall.setBackgroundResource(R.mipmap.red_ball_bg);
            }
            viewHold.tvBall.setText(data.get(position)+"");
        }


        return convertView;
    }
    class ViewHold {
        TextView tvBall;
        TextView tvSum;
    }
}
